//
//  CenterTabBarController.m
//  FuncFanc
//
//  Created by hubing on 2018/3/5.
//  Copyright © 2018年 huhu. All rights reserved.
//

#import "CenterTabBarController.h"
#import "PictureViewController.h"
#import "JokesViewController.h"
#import "MsgViewController.h"
#import "DesignViewController.h"
#import "FileViewController.h"

@interface CenterTabBarController ()
{
     NSArray *_tabConfigList;
}
@end

@implementation CenterTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.backgroundImage = [self imageWithColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0]];
    self.tabBar.shadowImage = [UIImage new];
    
    FileViewController *fileVc = [[FileViewController alloc]init];
    UINavigationController *fileNav = [[UINavigationController alloc]initWithRootViewController:fileVc];
    
    JokesViewController *joke = [[JokesViewController alloc]init];
    UINavigationController *videoNav = [[UINavigationController alloc]initWithRootViewController:joke];

//    MsgViewController *msg = [[MsgViewController alloc]init];
//    UINavigationController *msgNav = [[UINavigationController alloc]initWithRootViewController:msg];
    CordovaViewController *ionicWebVC = [[CordovaViewController alloc]init];
//    ionicWebVC.startPage = @"";
    
    DesignViewController *Design = [[DesignViewController alloc]init];
    UINavigationController *designNav = [[UINavigationController alloc]initWithRootViewController:Design];
    Design.view.backgroundColor = [UIColor whiteColor];
    self.viewControllers = @[fileNav,ionicWebVC,videoNav,designNav];
    _tabConfigList = @[@{@"title":@"文件",@"image":@"beauty",@"selectImage":@"watching"},
                       @{@"title":@"伊甸",@"image":@"flower",@"selectImage":@"watching"},
                       @{@"title":@"养眼",@"image":@"butterfly",@"selectImage":@"watching"},
                       @{@"title":@"设计",@"image":@"heart",@"selectImage":@"watching"}];
    for (int i = 0; i < _tabConfigList.count; i++)
    {
        NSDictionary *dict = [_tabConfigList objectAtIndex:i];
        UIImage *selectedImg = [[UIImage imageNamed:[dict objectForKey:@"selectImage"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ] ;
        UIImage *img = [[UIImage imageNamed:[dict objectForKey:@"image"]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        [self.tabBar.items objectAtIndex:i].selectedImage = selectedImg;
        [self.tabBar.items objectAtIndex:i].image = img;
        [(UITabBarItem *)[self.tabBar.items objectAtIndex:i] setTitle:[dict objectForKey:@"title"]];
        
        [[self.tabBar.items objectAtIndex:i] setTitlePositionAdjustment:UIOffsetMake(0, -2)];
        [[self.tabBar.items objectAtIndex:i] setImageInsets:UIEdgeInsetsMake(-2, 0, 2, 0)];
        [[self.tabBar.items objectAtIndex:i] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: RGBOF(0x919191),NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica-Bold" size:11],NSFontAttributeName,nil] forState:UIControlStateNormal];
        [[self.tabBar.items objectAtIndex:i] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica-Bold" size:11],NSFontAttributeName,nil] forState:UIControlStateSelected];
    }
    
}

- (UIImage *)imageWithColor:(UIColor *)color {
    
    CGRect rect = CGRectMake(0.0f,0.0f, 1.0f,1.0f);
    
    UIGraphicsBeginImageContext(rect.size);
    
    CGContextRef context =UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    
    CGContextFillRect(context, rect);
    
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
    
}
@end
